import {Component, Input, OnInit} from '@angular/core';
import {DhlCommonInputComponent} from '../dhlCommonInput';
import {ObjectUtil} from "../../../utils/object-util";
import {SwitchColor} from "../enums";

@Component({
  selector: 'dhl-switch',
  templateUrl: './dhl-switch.component.html'
})
export class DhlSwitchComponent extends DhlCommonInputComponent implements OnInit {

  uncheckedName;
  checkedName;
  style;
  colorClass = SwitchColor.GREEN;

  @Input() set colorType(value) {
    this.colorClass = value;
  };

  @Input() set width(value) {
    this.style = {width: value + 'px'};
  }

  @Input() set option(value) {
    if (ObjectUtil.isArray(value)) {
      this.checkedName = value[0];
      this.uncheckedName = value[1];
    }
  }

  constructor() {
    super();
  }


  ngOnInit() {
    this.inputWidth = this.labelWidth < 24 ? 24 - this.labelWidth : 1;
  }

  change() {
    if (this.onValueChange) {
      this.onValueChange(this.value);
    }
    this.valueChange.emit(this.value);
  }


}

